package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"log"
	"os"
	"strings"
)

func printContents(r io.Reader) {
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		text := scanner.Text()
		fmt.Println(text)
	}
}

func main() {
	file, err := os.Open("etcd.go")
	if err != nil {
		log.Fatalln(err)
	}
	defer func() { file.Close() }()
	printContents(file)

	r := strings.NewReader(`
		select id, name, age
		from t_user
		where id = ?
		and name = ?
		and age = ?`)
	printContents(r)

	r2 := bytes.NewReader([]byte(`select id, name, age
		from t_user
		where id = ?
		and name = ?
		and age = ?`))
	printContents(r2)
}
